<?php

use App\Kuafu\Invoice\Controller\Pos\InvoiceController;
use App\Kuafu\Mqtt\Controller\Pos\OnlineController;
use App\Kuafu\Mqtt\Controller\Pos\QueueController;
use App\Kuafu\Order\Controller\Pos\CouponController;
use App\Kuafu\Shop\Controller\Pos\PrinterController;
use App\Kuafu\User\Enum\UserCodeEnum;
use App\Kuafu\Wechat\Controller\Applet\WechatController;
use App\Kuafu\Wechat\Controller\Pos\WechatController as PosWechatController;
use Illuminate\Support\Facades\Route;
use App\Kuafu\User\Controller\Pos\LoginController;
use App\Kuafu\Product\Controller\Pos\ProductController;
use App\Kuafu\Category\Controller\Pos\CategoryController;
use App\Kuafu\User\Controller\Pos\UserController as PosUserController;
use App\Kuafu\Order\Controller\Pos\OrderController;
use App\Kuafu\Shop\Controller\Pos\ShopController;
use App\Kuafu\Dashboard\Controller\Pos\DashboardController;
use App\Kuafu\Pay\Controller\Pos\PayController;
use App\Kuafu\Config\Controller\Pos\ConfigController as PosConfigController;
use App\Kuafu\Order\Controller\Pos\CouponExtController;
use App\Kuafu\Shop\Controller\Pos\DeviceController;

/*
|--------------------------------------------------------------------------
| API POS Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

// 安卓 C端路由

//用户登录
Route::prefix('login')->group(function () {
    Route::post('', [LoginController::class, 'login']);
    Route::post('refresh', [LoginController::class, 'refresh']);
});

Route::middleware(['common.headerAuth', 'pos.shopStatusAuth', 'jwtAuth:' . UserCodeEnum::POS_TYPE])->group(function () {
    //用户中心
    Route::prefix('user')->group(function () {
        Route::get('', [PosUserController::class, 'getUserInfo']);
    });

    // 门店
    Route::prefix('shop')->group(function () {

        // 获取 MQTT 服务账号登录信息
        Route::get('/getMQTTAccount', [ShopController::class, 'getMQTTAccount']);

        // 获取队列
        Route::get('/queue', [QueueController::class, 'getQueue']);

        // 设置队列日志状态
        Route::post('/queue/setLogStatus', [QueueController::class, 'setLogStatus']);

        Route::get("/{shopId}", [ShopController::class, "getShopInfo"]);

        Route::post('/bandSerialNumber/{shopId}', [ShopController::class, "bandPosSerialNumber"]);

        Route::prefix('device')->group(function () {
            // 秒秒测
            Route::prefix('mmc')->group(function () {
                // 秒秒测设备绑定
                Route::post('/bind', [DeviceController::class, "bindMMC"]);
                // 秒秒测设备解绑
                Route::post('/rmBind', [DeviceController::class, "rmBindMMC"]);
                // 秒秒测设备列表
                Route::get('/list', [DeviceController::class, "listMMC"]);

                // 接收温度秒秒测数据
                Route::post('/temperatureData', [DeviceController::class, "temperatureData"]);
                // 查询温度秒秒测数据
                Route::get('/getTemperatureData', [DeviceController::class, "getTemperatureData"]);

            });
        });

    });

    // 菜品
    Route::prefix('product')->group(function () {
        // 店铺下的菜单、菜品、分类列表
        Route::get('/lists', [ProductController::class, 'lists']);
        // 操作估清、上下架
        Route::patch('/doStatus', [ProductController::class, 'doStatus']);
        // 添加菜品弹出可选菜品列表
        Route::get("/ordinaryProducts", [ProductController::class, 'ordinaryProducts']);
        // 添加菜品
        Route::post('/', [ProductController::class, 'insert']);
        // 菜品状态修改
        Route::patch('/{productId}', [ProductController::class, 'status']);
        // 更新菜品
        Route::put('/{productId}', [ProductController::class, 'update']);
        // 菜品详情
        Route::get('/{productId}', [ProductController::class, 'detail']);
        // 套餐删除
        Route::delete('/{productId}', [ProductController::class, 'delete']);
    });

    // 分类
    Route::prefix('category')->group(function () {

        // 分类列表
        Route::get('/lists', [CategoryController::class, 'lists']);
    });

    // Order
    Route::prefix('order')->group(function () {
        Route::get("/getOrderById/{orderId}", [OrderController::class, "getOrderById"]);
        Route::get("/getOrderByIdNew/{orderId}", [OrderController::class, "getOrderByIdNew"]);
        Route::post("/getOrderList", [OrderController::class, "getOrderList"]);
        // 下单
        Route::post("/", [OrderController::class, "order"])->middleware(['pos.shopStatusOrderAuth']);
        // 预计算
        Route::post('/preCalc', [OrderController::class, "preCalc"])->middleware(['pos.shopStatusOrderAuth']);
        // 获取订单支付状态
        Route::get("/payStatus/{orderId}", [OrderController::class, "getPayStatus"]);
        // 主动刷新订单支付状态
        Route::post('/refreshPayStatus/{orderId}', [OrderController::class, 'refreshPayStatus']);
        // 核销/撤销 优惠券
        Route::post("/checkCoupon", [OrderController::class, "checkCouponV2"])->middleware(['pos.shopStatusOrderAuth']);
        // 订单支付
        Route::prefix('pay')->group(function () {
            // 获取支付方式 - 老
            Route::get('/payment', [OrderController::class, "getPaymentList"]);
            // 获取支付方式 - 带上支付配置
            Route::get('/paymentList', [OrderController::class, "getPaymentListAll"]);
            // 现金支付
//            Route::post("/cashPay", [OrderController::class, "cashPay"]);
            // 被扫支付
            Route::post("/barPay", [OrderController::class, "barPay"]);

        });

        // 反结账
        Route::prefix('refund')->group(function () {
            // 反结账
            Route::post('/{orderId}', [OrderController::class, 'antiSettlementV6'])
                 ->middleware(['pos.shopStatusOrderAuth']);
        });
        // 叫号
        Route::get('/callNumber/{orderId}', [PosWechatController::class, 'callNumberSendMessage']);
        // 订单离线同步
        Route::post("/syncOrder", [OrderController::class, "syncOrder"]);
        // 店铺结算（日结单）
        Route::get('/calcShopTrade', [OrderController::class, 'calcShopTrade']);
        // 获取订单备注
        Route::get("/remark", [PosConfigController::class, "getOrderRemark"]);
        // 优惠券详情
        Route::prefix('coupon')->group(function () {
            // 【小红书优惠券码】详情
            Route::get('/xhsCouponDetail', [CouponExtController::class, 'getXhsCouponDetail']);
            // 美团优惠券详情
            Route::get('/meituan', [CouponExtController::class, 'getMeiTuanCouponInfo']);
            // 抖音优惠券详情
            Route::get('/douyin', [CouponExtController::class, 'getDouYinCouponInfo']);
            // 抖音优惠券详情关联商品详情
            Route::get('/douyinQuick', [CouponExtController::class, 'getDouYinCouponInfo']);
            // 内部券码信息查询
            Route::get('/insideCode', [CouponController::class, 'getCouponInfo']);
            // 校验优惠券是否能反核销 - 未使用
            Route::get('/meituan/checkCancel', [CouponExtController::class, 'checkCancelCoupon']);
            // 快速核销所有券
            Route::get('/quickAll', [CouponExtController::class, 'quickAll']);
        });

        // 外卖
        Route::prefix('waiMai')->group(function () {

            // 外卖订单列表
            Route::get('lists', [OrderController::class, 'waiMaiOrderLists']);

            // 外卖订单详情
            Route::get('detail', [OrderController::class, 'waiMaiOrderDetail']);

            // 商家出餐
            Route::post('finishFoods/{orderId}', [OrderController::class, 'finishFoods'])->where('orderId', '\d+');

            // 商家确认退款
            Route::post('confirmRefund/{orderId}', [OrderController::class, 'confirmRefund'])->where('orderId', '\d+');

            // 显示外卖出餐信息
            Route::get('getFinishFoodConfig', [OrderController::class, 'getFinishFoodConfig']);

            // 编辑外卖出餐信息
            Route::post('setFinishFoodConfig', [OrderController::class, 'setFinishFoodConfig']);

            // 查询外卖出餐承诺配置
            Route::get('getPromiseFinishConfig', [OrderController::class, 'getPromiseFinishConfig']);

            // 编辑外卖出餐承诺配置
            Route::post('setPromiseFinishConfig', [OrderController::class, 'setPromiseFinishConfig']);

            // 外卖出餐挂起
            Route::post('delayFinishFoodsConfig', [OrderController::class, 'delayFinishFoodsConfig']);
        });

        Route::prefix('invoice')->group(function () {
            // 开票
            Route::post('applyInvoice', [InvoiceController::class, 'applyInvoice']);

            // 发票红冲
            Route::post('redInvoice', [InvoiceController::class, 'redInvoice']);
        });


    });

    // 面板
    Route::prefix('dashboard')->group(function () {
        // 获取首页的店铺以及菜单列表
        Route::get('shop', [DashboardController::class, 'shopList'])->withoutMiddleware([
            'common.headerAuth',
            'pos.shopStatusAuth'
        ]);
        Route::get('auxiliaryScreen', [DashboardController::class, 'getAuxiliaryScreenRotation']);
        // 在线状态
        Route::get('onlineStatus', [DashboardController::class, 'onlineStatus']);
        // 获取配置接口
        Route::get('config', [PosConfigController::class, "get"]);
    });

    // 打印机
    Route::prefix('printer')->group(function () {
        // 获取列表
        Route::get('getPrinterList', [PrinterController::class, 'getPrinterList']);
        // 添加打印机
        Route::post('addPrinterData', [PrinterController::class, 'addPrinterData']);
        // 编辑打印机
        Route::post('setPrinter', [PrinterController::class, 'setPrinterData']);
        // 根据Id获取详情
        Route::get('getPrinterDetail', [PrinterController::class, 'getPrinterDetail']);
        // 删除打印机
        Route::post('delPrinter', [PrinterController::class, 'delPrinter']);
    });

    // 收银机配置
    Route::prefix('cashRegisterConfig')->group(function () {
        // 查询
        Route::get('/', [\App\Kuafu\Shop\Controller\Pos\ShopPosConfigController::class, 'info']);
        Route::post('update', [\App\Kuafu\Shop\Controller\Pos\ShopPosConfigController::class, 'update']);

    });
});

Route::prefix('outside')->group(function () {
    Route::any('mqttWebhook', [OnlineController::class, 'mqttWebhook']);
});
